package com.adms.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.adms.domain.Site;
import com.adms.service.SiteService;

@RequestMapping("site")
@RestController
public class SiteController {

	@Autowired
	private SiteService siteService;
	
	@GetMapping("{siteId}")
	public Object getBySiteId(@PathVariable("siteId") Integer siteId) {
		return siteService.getBySiteId(siteId);
	}
	
	@GetMapping("getWithCompleted")
	public Object getBySiteIdWithIsComplete(@RequestParam("siteId") Integer siteId) {
		return siteService.getBySiteIdWithCompleted(siteId);
	}
	
	@GetMapping
	public Object list(Site site,String timeField,Date start,Date end,String orderByClause,String key,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return siteService.list(site,timeField,start,end,orderByClause,key,pageNum,pageSize,navigatePages);
	}
	
	@GetMapping("listWithCompleted")
	public Object listWithIsComplete(Site site,String timeField,Date start,Date end,String orderByClause,String key,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return siteService.listWithCompleted(site,timeField,start,end,orderByClause,key,pageNum,pageSize,navigatePages);
	}
	
	@PostMapping("create")
	public Object create(Site site,int[] gridUserIds,Integer defaultGridUserId,
			int[] handleUserIds,Integer defaultHandleUserId,
			int[] legalUserIds,Integer defaultLegalUserId) {
		return siteService.create(site,gridUserIds,defaultGridUserId,handleUserIds,defaultHandleUserId,legalUserIds,defaultLegalUserId);
	}
	
	@PostMapping("update")
	public Object update(Site site,int[] gridUserIds,Integer defaultGridUserId,
			int[] handleUserIds,Integer defaultHandleUserId,
			int[] legalUserIds,Integer defaultLegalUserId) {
		return siteService.update(site,gridUserIds,defaultGridUserId,handleUserIds,defaultHandleUserId,legalUserIds,defaultLegalUserId);
	}
	
	@PostMapping("delete")
	public Object delete(Integer[] siteIds) {
		return siteService.delete(siteIds);
	}
}
